<?php


namespace App\Models\Wechat;


use App\Commons\Utils\ModelTools\BaseModel;
use App\Models\AdminUser\User;

class MiniProgramOperationRecord extends BaseModel {
    protected $dateFormat = 'Y-m-d H:i:s';

    protected $searchable = [
        'user_id',
        'ap_id',
        'open_appid',
        'wx_authorizer_appid',
        'op_name',
        'wx_auditid',
        'op_result',
        'result',
        'created_at',
        'mpt_id',
    ];

    protected $casts = [
        'op_result' => 'integer',
    ];

    /**
     * op_result 操作结果,0: 无结果记录，1：成功，2：失败
     */
    const OP_RESULT_NONE    = 0;
    const OP_RESULT_SUCCESS = 1;
    const OP_RESULT_FAIL    = 2;

    /**
     * 关联User用户表
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user() {
        return $this->belongsTo(User::class, 'user_id');
    }
    
    /**
     * 关联小程序/公众号项目
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function appProject() {
        return $this->belongsTo(\App\Models\App\AppProject::class, 'ap_id');
    }
    
    /**
     * 关联模板
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function miniProgramTemplate() {
        return $this->belongsTo(MiniProgramTemplate::class, 'mpt_id');
    }
}